package b1.scenes.home
{
	import b1.conifg.*;
	import b1.controls.basic.BasicMc;
	import b1.controls.basic.MessageBox;
	import b1.controls.basic.MessageBoxWithIcon;
	import b1.controls.basic.RoundRec;
	import b1.net.*;
	import b1.players.*;
	import b1.scenes.*;
	import b1.scenes.fight.*;
	import b1.utils.*;
	
	import com.greensock.TweenLite;
	import com.greensock.TimelineLite;
	import com.greensock.easing.Linear;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.Point;
	import flash.text.*;
	import flash.ui.Mouse;

	public class ObjectItem extends Sprite
	{
		private var objectIndex:int;
		private var objectNum:int;
		private var objectSprite:Sprite
		private var objectTip:Sprite;
		private var type:int;
		private var showSecond:int;
		
		//type, 0, 用在Home.BottomNavigator中; 1, 用在Fight.PackageNavigator中
		public function ObjectItem(TabItemBackground:Class, objectIndex:int, objectNum:int, type:int = 0)
		{
			super();
			showSecond = 0;
			this.objectIndex = objectIndex;
			this.objectNum = objectNum;
			var objectInfo:ObjectConfig = Config.objectConfigs[objectIndex];
			this.type = type;
			//背景框
			var tabItemBackground:Sprite = new TabItemBackground();
			if (type == 0)
			{
				tabItemBackground.width = 89;
				tabItemBackground.height = 110;
			}		
			else
			{
				tabItemBackground.width = 55;
				tabItemBackground.height = 60;
			}
			addChild(tabItemBackground);
			//标题名字
			if (type == 0)
			{
				var titleText:TextField = new TextField();
				titleText.selectable = false;
	        	titleText.autoSize = TextFieldAutoSize.LEFT;
	        	if (objectInfo.name.length < 6)
	        	{
	        		titleText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000, true);
	        	}
	        	else
	        	{
	        		titleText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0x000000, true);
	        	}
				
				titleText.text = objectInfo.name.substr(0,6);
				titleText.x = (tabItemBackground.width - titleText.width) / 2;
				titleText.y = 10;
				addChild(titleText);
			}
			//物品图片
			var ObjectImage:Class = ResourceHelper.getInstance().getClassByName(objectInfo.iconImage);   
			objectSprite = new ObjectImage();
			//家中
			if (type == 0)
			{
				//装备， 弓箭
				if (objectInfo.type == 2 || objectInfo.type == 3)
				{
					objectSprite.width = 40;
					objectSprite.height = 40;
					objectSprite.x = (tabItemBackground.width - objectSprite.width) / 2;
					objectSprite.y = (tabItemBackground.height - objectSprite.height) / 2;
				}
				//骨头，道具
				else
				{
					objectSprite.width = 25;
					objectSprite.height = 35;
					objectSprite.x = (tabItemBackground.width - objectSprite.width) / 2 - 10;
					objectSprite.y = (tabItemBackground.height - objectSprite.height) / 2 + 13;
					objectSprite.rotation = -40;
				}
			}
			//战斗中
			else if (type == 1)
			{
				//装备， 弓箭
				if (objectInfo.type == 2 || objectInfo.type == 3)
				{
					objectSprite.width = 30;
					objectSprite.height = 30;
					objectSprite.x = (tabItemBackground.width - objectSprite.width) / 2;
					objectSprite.y = 8;
				}
				//骨头，道具
				else
				{
					objectSprite.width = 13;
					objectSprite.height = 30;
					objectSprite.x = (tabItemBackground.width - objectSprite.width) / 2 - 8;
					objectSprite.y = 16;
					objectSprite.rotation = -40;
				}
			}
			//装备
			if (objectInfo.type == 2)
			{
				var equipConfig:EquipConfig = objectInfo as EquipConfig;
				if (equipConfig.color > 0)
				{
					var gradientGlow:GradientGlowFilter = new GradientGlowFilter();
					gradientGlow.distance = 0;
					gradientGlow.angle = 45;
					gradientGlow.colors = [0xFFFFFF, Config.equipColor2[equipConfig.color]];
					gradientGlow.alphas = [0, 1];
					gradientGlow.ratios = [0, 255];
					gradientGlow.blurX = 20;
					gradientGlow.blurY = 20;
					gradientGlow.strength = 2;
					gradientGlow.quality = BitmapFilterQuality.HIGH;
					gradientGlow.type = BitmapFilterType.OUTER;
					objectSprite.filters = [gradientGlow];
				}
			}
			addChild(objectSprite);
			
			//加载数量
			var numText:TextField = new TextField();
			numText.selectable = false;
			numText.autoSize = TextFieldAutoSize.LEFT;
			numText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			numText.text = objectNum.toString();
			numText.x = (this.width - numText.width) / 2;
			if (type == 0)
			{
				numText.y = 78;
			}
			else
			{
				numText.y = 33;
			}
			addChild(numText);
						
			addEventListener(MouseEvent.CLICK, onObjectItemClick);
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		//播放旋转动画
		private function playRotationMovie():void
		{
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			var objectConfig:ObjectConfig = Config.objectConfigs[this.objectIndex];
			var ObjectImage:Class = ResourceHelper.getInstance().getClassByName(objectConfig.iconImage);
			var objectImage:Sprite = new ObjectImage();   
			var rotationObject:Sprite = new Sprite;
			objectImage.x = -objectImage.width / 2;
			objectImage.y = -objectImage.height / 2;
			rotationObject.addChild(objectImage);
			var globalPoint:Point = localToGlobal(new Point(objectSprite.x, objectSprite.y));
			rotationObject.width = objectSprite.width;
			rotationObject.height = objectSprite.height;
			rotationObject.x = globalPoint.x;
			rotationObject.y = globalPoint.y;
			var destPosX:Number = fight.leftAnimal.x + fight.leftAnimal.launcher.x;
			var destPosY:Number = fight.leftAnimal.y + fight.leftAnimal.launcher.y;
			TweenLite.to(rotationObject, 0.5, {x:destPosX, y:destPosY, rotation: 1080 + fight.leftAnimal.launcher.rotation, onComplete:onPlayRotationMovieComplete, onCompleteParams:[rotationObject]}); 
			fight.addChild(rotationObject);
		}
		
		private function onPlayRotationMovieComplete(rotationObject:Sprite):void
		{
			if (rotationObject != null && rotationObject.parent != null)
			{
				rotationObject.parent.removeChild(rotationObject);
				var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
				var objectConfig:ObjectConfig = Config.objectConfigs[this.objectIndex];
				//骨头
				if (objectConfig.type == 0)
				{
					fight.leftAnimal.setPreparedBone(objectIndex);
					fight.leftAnimal.launcher.prepareBone(objectIndex);
				}
				//弓
				else if (objectConfig.type == 3)
				{
					fight.leftAnimal.getOnLauncher(objectIndex);
				}
			}	
		}
		
		private function onObjectItemClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().mouseDisableFlag && !SceneContainer.getInstance().checkOnlyMousePosition(event.currentTarget))
				return;
			//在战斗场景
			if (SceneContainer.getInstance().currentScene is Fight)
			{
				var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
				var objectConfig:ObjectConfig = Config.objectConfigs[this.objectIndex];
				fight.removeArmInhand();
				//骨头
				if (objectConfig.type == 0)
				{
					fight.managedIcon.disableManager();
					playRotationMovie();
				}
				//道具
				else if (objectConfig.type == 1)
				{
					fight.addArm(objectIndex);	
					//添加新手导引
					if (SceneContainer.getInstance().step == 24)
					{
						SceneContainer.getInstance().addStep();
					}
				}
				//弓（发射器）
				else if (objectConfig.type == 3)
				{
					fight.managedIcon.disableManager();
					playRotationMovie();
				}
				PackageNavigator.getInstance().hide();
			}
		}
		
		private function onButtonOKClick(event:MouseEvent):void
		{
			var me:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
			var myAnimal:AnimalInfo = PlayerInfoHelper.getInstance().animals[me.ownAnimals[0]];
			var equipConfig:EquipConfig = Config.objectConfigs[objectIndex];
			var oldEquipObjectIndex:int = 0;
			var oldEquipDurability:int = 0;
			var oldEquipInfo:EquipInfo = myAnimal.equips[equipConfig.position];
			if (SceneContainer.getInstance().step == 6)
			{
				SceneContainer.getInstance().addStep();
			}
			if (oldEquipInfo != null)
			{
				var oldEquipConfig:EquipConfig = Config.objectConfigs[oldEquipInfo.objectIndex];
				oldEquipObjectIndex = oldEquipInfo.objectIndex;
				oldEquipDurability = oldEquipInfo.durability;
			}
			ServerHelper.getInstance().getOnEquip(myAnimal.id, equipConfig.position, equipConfig.index, equipConfig.durability, oldEquipObjectIndex, oldEquipDurability, onGetOnEquipComplete); 
		}
		
		private function onGetOnEquipComplete(result:String):void
		{
			if (result == "success")
			{
				if (SceneContainer.getInstance().currentScene is Home)
				{
					var home:Home = SceneContainer.getInstance().currentScene as Home;
					var me:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
					var myAnimal:AnimalInfo = PlayerInfoHelper.getInstance().animals[me.ownAnimals[0]];
					var homeAnimal:HomeAnimal = home.homeAnimals[myAnimal.id];
					if (homeAnimal != null)
					{
						homeAnimal.refreshEquips();
					}
				}
			}
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			if ((SceneContainer.getInstance().step == 4 || SceneContainer.getInstance().step == 5 ||SceneContainer.getInstance().step == 6) && this.objectIndex != 37)
				return;
			this.filters = [new ColorMatrixFilter(
				[1,0,0,0,15,
			     0,1,0,0,15,
			     0,0,1,0,15,
			     0,0,0,1,0 ])];

			var objectInfo:ObjectConfig = Config.objectConfigs[objectIndex];
			objectTip = new Sprite();
			var roundRec:RoundRec;
			if (type == 0)
			{
				if (objectInfo.type == 2)
					roundRec = new RoundRec(150, 230, 0.8, BFont.roundRecColor);
				else
					roundRec = new RoundRec(120, 130, 0.8, BFont.roundRecColor);
			}
			else
			{
				Mouse.cursor = "button";
				roundRec = new RoundRec(130, 130, 0.8, BFont.roundRecColor);
			}
			objectTip.addChild(roundRec);
			
			//战斗中的物品可单击使用
			if (type == 1)
			{
				//“点击使用”
				var helpText:TextField = new TextField();
				helpText.selectable = false;
	        	helpText.width = roundRec.width;
	        	helpText.autoSize = TextFieldAutoSize.CENTER;
				var helpTexFormat:TextFormat = new TextFormat("微软雅黑", 15, 0x000000, true);
				helpTexFormat.leftMargin = 8;
				helpTexFormat.rightMargin = 8;
				helpTexFormat.color = 0x008000;
				helpText.defaultTextFormat = helpTexFormat;
				helpText.text = "单击使用";
				helpText.y = 5;
				objectTip.addChild(helpText);
			}
			//名字
			var nameText:TextField = new TextField();
			nameText.selectable = false;
        	nameText.width = roundRec.width;
        	nameText.autoSize = TextFieldAutoSize.LEFT;
			var nameTexFormat:TextFormat = new TextFormat("微软雅黑", 15, 0x000000, true);
			nameTexFormat.leftMargin = 8;
			nameTexFormat.rightMargin = 8;
			nameText.defaultTextFormat = nameTexFormat;
			//攻击，消耗体力，描述
			var levelText:TextField = new TextField();
			levelText.selectable = false;
        	levelText.autoSize = TextFieldAutoSize.LEFT;
        	levelText.width = roundRec.width;
        	levelText.wordWrap = true;
			var texFormat:TextFormat = new TextFormat("微软雅黑", 13, 0x000000);
			texFormat.leftMargin = 8;
			texFormat.rightMargin = 8;
			levelText.defaultTextFormat = texFormat;
			
			var qualityText:TextField = new TextField();
			qualityText.selectable = false;
        	qualityText.autoSize = TextFieldAutoSize.LEFT;
        	qualityText.width = roundRec.width;
        	qualityText.wordWrap = true;
			
			var suitEffect:TextField = new TextField();
			suitEffect.selectable = false;
        	suitEffect.autoSize = TextFieldAutoSize.LEFT;
        	suitEffect.width = roundRec.width;
        	suitEffect.wordWrap = true;
			suitEffect.defaultTextFormat = texFormat;
			
			if (objectInfo.type == 0)
			{
				levelText.text = "\n重量: " + objectInfo.weight + "\n作用: " + objectInfo.description;
			}
			else if (objectInfo.type == 1)
			{
				levelText.text = "作用: " + objectInfo.description;
			}
			else if (objectInfo.type == 2)
			{
				var equipConfig:EquipConfig = objectInfo as EquipConfig;
				var magicConfig:MagicConfig = Config.magicConfigs[equipConfig.magicIndex];
				if (equipConfig.durability == -1)
					levelText.appendText("耐久度: 永久\n");
				else
					levelText.appendText("耐久度: " + equipConfig.durability + "\n");
				levelText.appendText("魔法: " + magicConfig.name + "\n");
				levelText.appendText("作用: " + equipConfig.description.toString() + "\n");
				if (equipConfig.color > 0)
				{
					var colorTextFormat:TextFormat = new TextFormat("微软雅黑", 13, Config.equipColor1[equipConfig.color], true);
					colorTextFormat.leftMargin = 8;
					colorTextFormat.rightMargin = 8;
					qualityText.y = levelText.y + levelText.height + 20;
					qualityText.defaultTextFormat = colorTextFormat;
					qualityText.text = "品质: " + Config.equipColorName[equipConfig.color] + "  " + equipConfig.colorDescribe;
					var colorNameFormat:TextFormat = new TextFormat("微软雅黑", 15, Config.equipColor1[equipConfig.color], true);
					colorNameFormat.leftMargin = 8;
					colorNameFormat.rightMargin = 8;
					nameText.defaultTextFormat = colorNameFormat;
					suitEffect.y = qualityText.y + qualityText.height - 5 ;
				}
				else
				{
					suitEffect.y = levelText.y + levelText.height + 20;
				}
				magicConfig = Config.magicConfigs[equipConfig.wholeMagicIndex];
				suitEffect.text = "整套附加: " + equipConfig.wholeEquipDescription.toString();
				suitEffect.appendText("\n整套魔法: " + magicConfig.name);
			}
			//弓箭
			else if (objectInfo.type == 3)
			{
				levelText.text = objectInfo.description;
			}
			//战斗场景中
			if (type == 1)
			{
				if (objectInfo.type == 0) 
					levelText.y = nameText.y + 25;
				else
					levelText.y = nameText.y + 45;
			}
			//家中
			else
			{
				if (objectInfo.type == 0)
					levelText.y = nameText.y + 5;
				else
					levelText.y = nameText.y + 25;
			}
			nameText.text = objectInfo.name.toString();
			if (type == 1)
			{
				nameText.y = 25;
			}
			else
			{
				nameText.y = 5;
			}
			objectTip.addChild(nameText);
			objectTip.addChild(levelText);
			objectTip.addChild(qualityText);
			objectTip.addChild(suitEffect);
			if (type == 0)
			{
				var sellText:TextField = new TextField();
				sellText.selectable = false;
	        	sellText.autoSize = TextFieldAutoSize.LEFT;
	        	texFormat = new TextFormat("微软雅黑", 13, 0x0000FF);
	        	texFormat.leftMargin = 8;
				texFormat.rightMargin = 8;
	        	texFormat.underline = true;
				sellText.defaultTextFormat = texFormat;
				sellText.text = "出售";
				if (objectInfo.type != 2)
				{
					sellText.y = nameText.y + 80;
				}
				else
				{
					sellText.y = suitEffect.y + suitEffect.height + 5;
				}
				sellText.addEventListener(MouseEvent.MOUSE_OVER, onSellOver);
				sellText.addEventListener(MouseEvent.MOUSE_OUT, onSellOut);
				sellText.addEventListener(MouseEvent.CLICK, onSellClick);
				if (this.objectIndex != 0)
					objectTip.addChild(sellText);
				//如果是装备 加上装备
				if (objectInfo.type == 2)
				{
					var equipText:TextField = new TextField();
					equipText.selectable = false;
		        	equipText.autoSize = TextFieldAutoSize.LEFT;
		        	texFormat = new TextFormat("微软雅黑", 13, 0x0000FF);
		        	texFormat.leftMargin = 8;
					texFormat.rightMargin = 8;
		        	texFormat.underline = true;
					equipText.defaultTextFormat = texFormat;
					equipText.text = "装备";
					if (objectInfo.type != 2)
					{
						equipText.y = nameText.y + 80;
					}
					else
					{
						equipText.y = sellText.y;
					}
					equipText.x = sellText.x + 45;
					equipText.addEventListener(MouseEvent.MOUSE_OVER, onSellOver);
					equipText.addEventListener(MouseEvent.MOUSE_OUT, onSellOut);
					equipText.addEventListener(MouseEvent.CLICK, onEquipClick);
					objectTip.addChild(equipText);
				}
				if (objectInfo.type == 1 && (objectInfo.effects[30] != null || objectInfo.effects[31] != null))
				{
					var useText:TextField = new TextField();
					useText.selectable = false;
		        	useText.autoSize = TextFieldAutoSize.LEFT;
		        	texFormat = new TextFormat("微软雅黑", 13, 0x0000FF);
		        	texFormat.leftMargin = 8;
					texFormat.rightMargin = 8;
		        	texFormat.underline = true;
					useText.defaultTextFormat = texFormat;
					useText.text = "使用";
					if (objectInfo.type != 2)
					{
						useText.y = nameText.y + 80;
					}
					else
					{
						useText.y = sellText.y;
					}
					useText.x = sellText.x + 45;
					useText.addEventListener(MouseEvent.MOUSE_OVER, onSellOver);
					useText.addEventListener(MouseEvent.MOUSE_OUT, onSellOut);
					if (objectInfo.effects[30] != null)
					{
						useText.addEventListener(MouseEvent.CLICK, onFindHeirloomClick);
					}
					else if (objectInfo.effects[31] != null)
					{
						useText.addEventListener(MouseEvent.CLICK, onFindRunawayClick);
					}
					objectTip.addChild(useText);
				}
				objectTip.x = this.x + 165 - objectTip.width / 2;
				objectTip.y = 490 + this.y - objectTip.height - 15;
				BottomNavigator.getInstance().showTip(objectTip);
				BottomNavigator.getInstance().mouseOverFlag = true;
			}
			else
			{
				objectTip.x = 125 + this.x - objectTip.width / 2;
				objectTip.y = 527 + this.y - objectTip.height;
				SceneContainer.getInstance().currentScene.addChild(objectTip);
			}
		}    
		
		//点击追踪逃犯，弹出对话框
		private function onFindRunawayClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().currentScene is Home)
			{
				var home:Home = SceneContainer.getInstance().currentScene as Home;
				if (home.liveId > 0)
				{
					var message:String = "立即飞往" + (PlayerInfoHelper.getInstance().players[home.liveId] as PlayerInfo).name + "的动物所在的位置?";
					var objectInfo:ObjectConfig = Config.objectConfigs[objectIndex];
					var messageBox:MessageBoxWithIcon = new MessageBoxWithIcon(message, objectInfo.iconImage, "竹蜻蜓", 1, true);
					messageBox.x = BFont.stageWidth / 2;
					messageBox.y = BFont.stageHeight / 2;
					messageBox.buttonOK.addEventListener(MouseEvent.CLICK, onFindRunawayButtonOKClick);
					SceneContainer.getInstance().currentScene.addChild(messageBox);
				}
				else
				{
					message = "不能飞往虚拟人物的动物。";
					messageBox = new MessageBoxWithIcon(message, objectInfo.iconImage, "竹蜻蜓");
					messageBox.x = BFont.stageWidth / 2;
					messageBox.y = BFont.stageHeight / 2;
					SceneContainer.getInstance().currentScene.addChild(messageBox);
				}
				BottomNavigator.getInstance().hide();
			}
		}
		
		//点击确定后开始发送请求
		private function onFindRunawayButtonOKClick(event:MouseEvent):void
		{
			var boneBalance:String = "";
			boneBalance += PlayerInfoHelper.getInstance().userId + "," + this.objectIndex + ",-1";
			ServerHelper.getInstance().findCrimerSite((SceneContainer.getInstance().currentScene as Home).liveId, boneBalance, onFindRunawayComplete);
		}
		
		//处理请求
		private function onFindRunawayComplete(crimerLiveId:int):void
		{
			var player:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
			(SceneContainer.getInstance().currentScene as Home).switchLiveId(crimerLiveId,false);
			playDragonflyMovie(1);
		}
		
		//点击追踪传家骨头，弹出messagebox
		private function onFindHeirloomClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().currentScene is Home)
			{
				var objectInfo:ObjectConfig = Config.objectConfigs[objectIndex];
				var  message:String = "立即飞往你的传家骨的位置？";
				var messageBox:MessageBoxWithIcon = new MessageBoxWithIcon(message, objectInfo.iconImage, "竹蜻蜓", 1, true);
				messageBox.x = BFont.stageWidth / 2;
				messageBox.y = BFont.stageHeight / 2;
				SceneContainer.getInstance().currentScene.addChild(messageBox);
				messageBox.buttonOK.addEventListener(MouseEvent.CLICK, onFindHeirloomButtonOKClick);
				BottomNavigator.getInstance().hide();
			}
		}
		
		//确定和处理
		private function onFindHeirloomButtonOKClick(event:MouseEvent):void
		{
			var boneBalance:String = "";
			boneBalance += PlayerInfoHelper.getInstance().userId + "," + this.objectIndex + ",-1";
			ServerHelper.getInstance().findCrimerHome(PlayerInfoHelper.getInstance().userId, boneBalance, onFindHeirloomComplete);
		}
		
		private function onFindHeirloomComplete(crimerOwnerId:int, crimerLiveId:int):void
		{
			var player:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
			(SceneContainer.getInstance().currentScene as Home).switchLiveId(crimerOwnerId,false);
			playDragonflyMovie(0);
		}

		//播放竹蜻蜓动画
		private function playDragonflyMovie(index:int):void
		{
			var DragonflyMovie:Class = ResourceHelper.getInstance().getClassByName("Dragonfly" + index + "Movie");
			var dragonFlyMc:BasicMc = new BasicMc(DragonflyMovie);
			dragonFlyMc.x = 500;
			dragonFlyMc.y = 450;
			var myTimeline:TimelineLite = new TimelineLite();
			myTimeline.append(new TweenLite(dragonFlyMc, 1.5, {x:80, y:50, rotation: 30, scaleX:4, scaleY:4, ease:Linear.easeNone}));
			myTimeline.append(new TweenLite(dragonFlyMc, 1.5, {x:850, y:400, rotation: 60, scaleX:8, scaleY:8, ease:Linear.easeNone, onComplete:playDragonflyMovieComplete, onCompleteParams:[dragonFlyMc]}));
			SceneContainer.getInstance().currentScene.addChild(dragonFlyMc);
		}
		
		private function playDragonflyMovieComplete(dragonFlyMc:BasicMc):void
		{
			if (dragonFlyMc != null && dragonFlyMc.parent != null)
			{
				dragonFlyMc.parent.removeChild(dragonFlyMc);
			}	
		}

		 //装上装备
		private function onEquipClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().currentScene is Home)
			{
				//使用装备
				var objectConfig:ObjectConfig = Config.objectConfigs[this.objectIndex];
				objectConfig = Config.objectConfigs[objectIndex];
				if (objectConfig.type == 2)
				{
					var home:Home = SceneContainer.getInstance().currentScene as Home;
					var me:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
					var myAnimal:AnimalInfo = PlayerInfoHelper.getInstance().animals[me.ownAnimals[0]];
					var msgBox:MessageBox;
					if (home.liveId != PlayerInfoHelper.getInstance().userId)
					{
						msgBox = new MessageBox("在别人家中，不能绑定装备……");
						msgBox.x = (BFont.stageWidth - msgBox.width) / 2;
						msgBox.y = (BFont.stageHeight - msgBox.height) / 2;
						home.addChild(msgBox);
					}
					else if (myAnimal.liveId != PlayerInfoHelper.getInstance().userId)
					{
						msgBox = new MessageBox("你的动物不在家中，不能绑定装备……");
						msgBox.x = (BFont.stageWidth - msgBox.width) / 2;
						msgBox.y = (BFont.stageHeight - msgBox.height) / 2;
						home.addChild(msgBox);
					}
					else
					{
						var equipConfig:EquipConfig = objectConfig as EquipConfig;
						var oldEquipInfo:EquipInfo = myAnimal.equips[equipConfig.position];
						var message:String;
						if (oldEquipInfo != null)
						{
							var oldEquipConfig:EquipConfig = Config.objectConfigs[oldEquipInfo.objectIndex];
							if (oldEquipInfo.durability != -1)
								message = "原装备 " + oldEquipConfig.name + " 是非永久物品，\n卸载后将被永久丢弃。是否继续？";
							else
								message = "原装备 " + oldEquipConfig.name + " 是永久物品，\n卸载后将被放入包裹。是否继续？";
						}
						else
						{
							if (equipConfig.durability != -1)
								message = equipConfig.name + " 是非永久物品，\n装备之后将无法重回包裹。是否继续？";
							else
								message = equipConfig.name + " 是永久物品，\n可自由装卸。是否继续？";
						}
						var messageBox:MessageBox = new MessageBox(message, 1, true);
						messageBox.x = (BFont.stageWidth - messageBox.width) / 2;
						messageBox.y = (BFont.stageHeight - messageBox.height) / 2;
						SceneContainer.getInstance().currentScene.addChild(messageBox);
						if (SceneContainer.getInstance().step == 5)
						{
							SceneContainer.getInstance().addStep();
						}
						messageBox.buttonOK.addEventListener(MouseEvent.CLICK, onButtonOKClick);
					}
					BottomNavigator.getInstance().hide();
				}
			}
		}
		
		private function onSellOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
		}
		
		private function onSellOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
		}
		
		//卖出物品
		private function onSellClick(event:MouseEvent):void
		{
			var objectConfig:ObjectConfig;
			objectConfig = Config.objectConfigs[objectIndex];
			var purchaseDialog:PurchaseDialog = new PurchaseDialog(objectConfig, 1);
			purchaseDialog.x = (BFont.stageWidth - purchaseDialog.width) / 2;
			purchaseDialog.y = (BFont.stageHeight - purchaseDialog.height) / 2;
			SceneContainer.getInstance().currentScene.addChild(purchaseDialog);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().step == 4 ||SceneContainer.getInstance().step == 5)
			{
				return;
			}
			if (type == 1)
				Mouse.cursor = "auto";
			this.filters = null;
			if (null != objectTip.parent && (SceneContainer.getInstance().currentScene is Fight))
			{
				objectTip.parent.removeChild(objectTip);
			}
			if (null != objectTip.parent && (SceneContainer.getInstance().currentScene is Home))
			{
				BottomNavigator.getInstance().mouseOverFlag = false;
			}
		} 
	}
}